<template>
	<view class="all">
		<view class="top">
			<image class="top_img" src="../../static/dw.png"></image>
			<view class="top_rights">
				<view>收货人 : {{orderInfo.contactor}} <text>{{orderInfo.contactor_phone}}</text></view>
				<view class="address"><view class="addressa">收货地址：</view><view>{{orderInfo.address}}</view></view>
			</view> 
		</view>
		<view class="xian">
			<image class="top_img2" src="../../static/xian.png"></image>
		</view>
		<view class="content">
			<view class="list">
				<view class="lista">
					<view class="list_top">
						<view>订单编号：{{orderInfo.order_sn}}</view>
						<!-- <view>{{orderInfo.create_time_text}}</view> -->
					</view>
					<view class="j_lista" v-for="item in orderInfo.products" @click="toProduct(item)" :key='item.id'>
						<image class="t_img" :src="item.images[0]"></image>
						<view class="j_right">
							<view class="t_title">{{item.title}}</view>
							<view class="price2">
								<view>￥<text class="bigs">{{item.price || '0.00'}}</text></view>
								<view>{{item.quantity}}</view>
							</view>
						</view>
					</view>
				</view>
				<view class="list_bot">
					<view>配送费</view>
					<view>{{orderInfo.delivery_price || '0.00'}}</view>
				</view>
				<view class="list_bot list_bot2">
					<view>优惠</view>
					<view>{{orderInfo.discount_price || '0.00'}}</view>
				</view>
				<view class="dingdan">
					订单信息
				</view>
				<view class="list_bot3">
					<view>订单编号</view>
					<view class="bot3_right">{{orderInfo.order_sn}}</view> 
					<view style="color: #007AFF;" @click="wuliu(orderInfo.express_no)" v-if="orderInfo.is_delivery == 1">物流跟踪</view>
				</view>
				<view class="list_bot3">
					<view>下单时间</view>
					<view class="bot3_right">{{orderInfo.create_time_text}}</view>
				</view>
			</view>
			<view class="bottoms">
				<view class="bot_text">共计1件商品  合计：<text class="reds">{{orderInfo.order_price || '0.00'}}</text></view>
				<view class="bot_btns" v-if="orderInfo.status == 0">
					<view class="bot_btnsa" @click="cancelOrder(orderInfo.order_sn)">取消订单</view>
					<view class="bot_btnsb" @click="goPay(orderInfo.order_sn)">立即支付</view>
				</view>
				<view class="bot_btns" style="background: #999999;"  v-if="orderInfo.is_delivery == 0 && orderInfo.status != 0 &&  orderInfo.status != -1">
					<view class="bot_btnsa" >待发货</view>
				</view>
				<view class="bot_btns" v-if="orderInfo.status == 1 && orderInfo.is_delivery != 0">
					<view class="bot_btnsa" @click="receive(orderInfo.order_sn)">确认收货</view>
				</view>
				<view class="bot_btns" v-if="orderInfo.status == 2 && orderInfo.state_tip !='已完成'">
					<view class="bot_btnsa btns_pj" @click="goReview()">评价</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				orderInfo: {},
				order_sn: null,
				state: 0
			}
		},
		onLoad(option) {
			this.order_sn = option.order_sn
			this.state = option.state
			this.loadData()
		},
		methods: {
			loadData() {
				this.$http.get('order.info', {
					order_sn: this.order_sn
				}).then(res => {
					this.orderInfo = res.data
				})
			},
			toProduct(item) {
				uni.navigateTo({
					url: '/pages/product/product?id=' + item.product_id
				})
			},
			toReview(item) {
				uni.navigateTo({
					url: '/pages/order/review?id=' + item.id + '&state=' + this.state
				})
			},
			//取消订单
			cancelOrder(order_sn){
				let form = {
					order_sn: order_sn
				}
				uni.showModal({
					content: '确认取消订单吗？',
					success: (e) => {
						if (e.confirm) {
							this.$http.post('order.cancel', form).then(res => {
								if(res.code == 1){
										this.$api.msg(res.data.msg);
										uni.redirectTo({
											url: '/pages/order/order?state=1',
											success() {
												var page = getCurrentPages().pop();
												if (page == undefined || page == null) return; 
												page.loadData(); 
											}
										})
								}
							})
						}
					}
				})
			},
			goPay(order_sn) {
				uni.navigateTo({
					url: '/pages/money/pay?order_sn=' + order_sn
				})
			},
			// 订单收货
			receive(order_sn) {
				let form = {
					order_sn: order_sn
				}
				uni.showModal({
					content: '确认收货吗？',
					success: (e) => {
						if (e.confirm) {
							this.$http.post('order.receive', form).then(res => {
										uni.redirectTo({
											url: '/pages/order/order?state=2',
											success() {
												var page = getCurrentPages().pop();
												if (page == undefined || page == null) return; 
												page.loadData(); 
											}
										})
							})
						}
					}
				})
					
			},
			//评论
			goReview() {
				uni.navigateTo({
					url: `/pages/order/review?id=${this.orderInfo.products[0].id}&state=${this.orderInfo.state}`
				})
			},
			wuliu(url){
				plus.runtime.openURL('https://m.kuaidi100.com/result.jsp?nu=' + url)  
			}
		}
	}
</script>

<style lang="scss">
	page{
		width: 100%;
		font-size: 30upx;
	}
	.top,.list_top,.list_bot{
		display: flex;
		justify-content: flex-start;
		align-items: center;
	}
	.list_bot3{
		display: flex;
		justify-content: space-between;
		align-items: center;
	}
	.top{
		width: 100%;
		padding: 20upx;
	}
	.top_img{
		width: 60upx;
		height: 70upx;
	}
	.xian{
	}
	.top_img2{
		width: 100%;
		height: 25upx;
	}
	.top_rights{
		width: 85%;
		padding-left: 30upx;
	}
	.address{
		display: flex;
		justify-content: flex-start;
		padding-top: 15upx;
	}
	.addressa{
		width: 35%;
	}
	.content{
		/* padding: 20upx; */
	}
	.list{
		padding: 20upx 20upx 90upx 20upx;
	}
	.lista{
		padding: 15upx;
		border-radius: 10upx;
		box-shadow:0 3upx 5upx 5upx #F2F2F2;
	}
	.list_top{
		padding: 25upx 0;
		justify-content: space-between;
		border-bottom: 1upx dashed #F2F2F2;
	}
	.j_lista{
		padding: 10upx 0;
		display: flex;
		justify-content: space-between;
		align-items: center;
	}
	.j_right{
		padding-left: 20upx;
		width: 70%;
	}
	.price2{
		padding: 20upx 0!important;
		display: flex;
		justify-content: space-between;
		align-items: center;
	}
	.j_lista_bot{
		text-align: right;
		padding: 0 30upx;
	}
	.grays{
		color: #848484;
	}
	.bigs2{
		font-size: 38upx;
	}
	.t_img{
		width: 150upx;
		height: 150upx;
		border-radius: 5upx;
		box-shadow: 0 0 10upx 3upx gray;
		margin: 10upx;
	}
	.list_bot{
		justify-content: space-between;
		padding: 30upx;
	}
	.list_bot2{
		border-top: 5upx solid #F8F8F8;
		border-bottom: 25upx solid #F8F8F8;
	}
	.dingdan{
		text-indent: 20upx;
		border-left: 8upx solid #FF4937;
		margin: 30upx 0;
	}
	.list_bot3{
		padding: 20upx 0!important;
	}
	.bot3_right{
		padding-left: 50upx;
	}
	.bottoms{
		position: fixed;
		bottom: 0;
		width: 100%;
		display: flex;
		justify-content: space-between;
		align-items: center;
		border-top: 1upx solid #F2F2F2;
	}
	.bot_text{
		text-indent: 20upx;
	}
	.reds{
		color: #FF4937;
		font-size: 35upx;
	}
	.bot_btns{
		padding: 15upx 0;
		display: flex;
		justify-content: flex-end;
		background: #FF1F01;
		color: #FFFFFF;
	}
	.bot_btns view{
		padding: 10upx 15upx;
	}
	.bot_btnsb{
		border-left: 1px solid #FFFFFF;
	}
	.btns_pj{
		width: 180upx;
		text-align: center;
	}
// 	.order-detail-content {
// 		font-size: $font-base;
// 		color: #555;
// 
// 		.list {
// 			display: flex;
// 			flex-direction: column;
// 			.item {
// 				display: flex;
// 				flex-direction: row;
// 				padding: 10upx;
// 
// 				image {
// 					width: 100px;
// 					height: 100px;
// 				}
// 
// 				.text {
// 					display: flex;
// 					flex-direction: column;
// 					flex: 1;
// 					padding: 10upx;
// 
// 					.title {
// 						display: -webkit-box;
// 						-webkit-box-orient: vertical;
// 						-webkit-line-clamp: 2;
// 						line-height: 150%;
// 						overflow: hidden;
// 					}
// 
// 					.spec {
// 						margin: 10upx 0;
// 						font-size: $font-base - 2upx;
// 						color: gray;
// 					}
// 				}
// 
// 				.append {
// 					display: flex;
// 					flex-direction: column;
// 					justify-content: center;
// 					align-items: center;
// 					padding: 0 16upx;
// 
// 					.quantity {
// 						margin-top: 10upx;
// 						font-size: $font-base - 4upx;
// 						color: gray;
// 					}
// 				}
// 			}
// 		}
// 
// 		.total-box {
// 			padding: 20upx;
// 
// 			.desc-item {
// 				display: flex;
// 				justify-content: space-between;
// 				margin: 20upx 0;
// 				color: gray;
// 				text {
// 					font-size: $font-base - 2upx;
// 				}
// 				&.total text {
// 					color: #555;
// 					font-size: $font-base + 2upx;
// 				}
// 				&.pay-total {
// 					margin-top: 16upx;
// 					padding-top: 16upx;
// 					border-top: 1px solid #ccc;
// 					text {
// 						color: #444;
// 						font-size: $font-base + 2upx;
// 						font-weight: 700;
// 					}
// 				}
// 				&.coupon {
// 					color: #fa436a;
// 				}
// 
// 
// 			}
// 		}
// 		.action-box{
// 			display: flex;
// 			justify-content: flex-end;
// 			align-items: center;
// 			height: 100upx;
// 			position: relative;
// 			padding-right: 30upx;
// 		}
// 		.action-btn{
// 			width: 160upx;
// 			height: 60upx;
// 			margin: 0;
// 			margin-left: 24upx;
// 			padding: 0;
// 			text-align: center;
// 			line-height: 60upx;
// 			font-size: $font-sm + 2upx;
// 			color: $font-color-dark;
// 			background: #fff;
// 			border-radius: 100px;
// 			&:after{
// 				border-radius: 100px;
// 			}
// 			&.recom{
// 				background: #fff9f9;
// 				color: $base-color;
// 				&:after{
// 					border-color: #f7bcc8;
// 				}
// 			}
// 		}
// 	}
</style>
